package org.springboot.szsrcb.controller;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.sql.Blob;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springboot.szsrcb.entity.Attachment;
import org.springboot.szsrcb.entity.Req_base_info;
import org.springboot.szsrcb.entity.Req_bill;
import org.springboot.szsrcb.entity.Req_team_info_log;
import org.springboot.szsrcb.entity.Req_workload_info;
import org.springboot.szsrcb.entity.Test_bill;
import org.springboot.szsrcb.entity.User;
import org.springboot.szsrcb.srvice.Att_Service;
import org.springboot.szsrcb.srvice.Query_Service;
import org.springboot.szsrcb.srvice.RTX_Service;
import org.springboot.szsrcb.srvice.Req_bill_Service;
import org.springboot.szsrcb.srvice.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;



@RestController
@RequestMapping("/req")
public class ReqRestController {

	private static final Logger logger = LoggerFactory.getLogger(ReqRestController.class);

	@Autowired
	private Req_bill_Service req_bill_Service;
	
	@Autowired
	private UserService userService;

	@Autowired
	private Att_Service att_Service;
	
	@Autowired
	private RTX_Service rtx_Service;
	
	@RequestMapping(value = "/get_req_remark")
	public String get_req_remark(HttpServletRequest request) {
		String result="";
		
		logger.info("进入 test_assign_page_remark 处理");
		
		String id=request.getParameter("req_id");
		
		Req_base_info r= req_bill_Service.search_req_base_info(id);
		if (r != null) {
			result=r.getReq_remark();
		}
		return result;
	}
	
	
	
	@RequestMapping(value = "/get_node_value_date")
	public String get_node_value_date(HttpServletRequest request,Model model,Req_base_info req_base_info) {
		String result="";
		
		logger.info("进入 get_node_value_date 处理");
		
		model.addAttribute("Req_base_info", req_base_info);
		int g_req_id=Integer.valueOf(req_base_info.getReq_id());
		Date r=req_bill_Service.search_node_value_date_by_req_id_and_value(g_req_id, req_base_info.getNode_value());
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		if (r != null) {
			return sdf.format(r);
		}else{
			return "";
		}
		
	}
	
	
	@RequestMapping(value = "/get_req_introduction")
	public String get_req_introduction(HttpServletRequest request) {
		String result="";
		
		logger.info("进入 get_req_introduction 处理");
		
		String id=request.getParameter("req_id");
		
		Req_base_info r= req_bill_Service.search_req_base_info(id);
		if (r != null) {
			result=r.getReq_introduction();
		}
		return result;
	}

	
	@RequestMapping("/req_assign_detail_page_del_att")
	public boolean req_assign_detail_page_del_att(HttpServletRequest request,HttpServletResponse response ) {
		boolean result=false;
		String get_att_id=(String) request.getParameter("att_id");
		result=att_Service.del_a_att_by_id(get_att_id);	
		
		return result;
	}
	
	@RequestMapping("/req_new_save")
	public boolean req_new(HttpServletRequest request, Model model, Req_bill req_bill) {
		boolean result;
		model.addAttribute("Req_bill", req_bill);
		logger.info("req_bill_no:" + req_bill.getReq_bill_no());
		logger.info("Req_titile:" + req_bill.getReq_title());
		logger.info("request.getMethod:" + request.getMethod());
		result = req_bill_Service.save_req_bill(req_bill);

		return result;
	}
	
	
	
	//@RequestMapping("/req_assign_save")
	@RequestMapping(value = "/req_assign_save", method = { RequestMethod.POST })
	public boolean req_assign_save(HttpServletRequest request, Model model, Req_base_info req_base_info) {
		boolean result;
		model.addAttribute("Req_base_info", req_base_info);
		logger.info("req_bill_no:" + req_base_info.getReq_bill_no());
		logger.info("Req_titile:" + req_base_info.getReq_title());
		logger.info("request.getMethod:" + request.getMethod());
		result = req_bill_Service.save_req_base_info(req_base_info);
		
		if(result){
			String msg="";
			String rtx_account=null;
			String getReq_head="";
			String getReq_analyst="";
			String getReq_supervisor="";
			getReq_head=req_base_info.getReq_head();
			getReq_analyst=req_base_info.getReq_analyst();
			getReq_supervisor=req_base_info.getReq_supervisor();
			Req_bill req_bill=req_bill_Service.req_bill_search_by_id(req_base_info.getReq_id());
			msg=req_bill.getReq_bill_no()+" "+req_bill.getReq_title()+" 已分配，需求负责人【"+getReq_head+"】,"
					+ "需求分析人员【"+getReq_analyst+"】,需求监理【"+getReq_supervisor+"】,请知悉并即时处理";
			List<User> u_l=new ArrayList<User>();
			User u_tmp=null;
			u_tmp=userService.search_a_user_by_name(req_base_info.getReq_head());
			u_l.add(u_tmp);
			
			String[] users=getReq_analyst.split(",");
			for (int i = 0; i < users.length; i++) {
				if(!users[i].equals(getReq_head)){
				u_tmp=userService.search_a_user_by_name(users[i]);
				u_l.add(u_tmp);
				//rtx_Service.send_message(msg, u_tmp2.getRtx_account());
				}
			}
			
			String[] users2=getReq_supervisor.split(",");
			for (int i = 0; i < users2.length; i++) {
				boolean is_add=true;
				for (int j = 0; j < u_l.size(); j++) {
					String s = u_l.get(j).getName();
					if(s.equals(users2[i])){
						is_add=false;
					}
				}
				if(is_add){
					u_tmp=userService.search_a_user_by_name(users2[i]);
					u_l.add(u_tmp);
				}
			}
			
			
			for (int j = 0; j < u_l.size(); j++) {
				u_tmp = u_l.get(j);
				rtx_account=u_tmp.getRtx_account();
				if(rtx_account!=null){
					logger.info("msg="+msg+" rtx_account="+rtx_account);
					rtx_Service.send_message(msg, rtx_account);
				}
			}
			
			
		}
		return result;
	}

	
	
	@RequestMapping(value = "/req_modify_base_info_save", method = { RequestMethod.POST })
	public boolean req_modify_base_info_save(HttpServletRequest request, Model model, Req_base_info req_base_info) {
		boolean result;
		logger.info("req_modify_base_info_save " + request.getMethod());
		logger.info("req_id:" + req_base_info.getReq_id());
		result = req_bill_Service.save_req_base_info(req_base_info);

		return result;
	}
	
	
	@RequestMapping(value = "/req_modify_base_info_save_att", method = { RequestMethod.POST })
	public boolean req_modify_base_info_save_att(HttpServletRequest request, Model model, Req_base_info req_base_info) {
		boolean result=false;
		logger.info("req_modify_base_info_save " + request.getMethod());
		logger.info("req_id:" + req_base_info.getReq_id());
		// req_bill_Service.save_req_base_info(req_base_info);
		
		String atts = req_base_info.getAtt_id();
		if (atts != null && !atts.equals("")) {
			result =req_bill_Service.update_req_base_info_att(req_base_info.getReq_id(), atts);
		}
		return result;
	}
	
	@RequestMapping(value = "/req_reject_save", method = { RequestMethod.POST })
	public boolean req_reject_save(HttpServletRequest request) {
		boolean result=false;
		
		logger.info("进入 req_reject_save 处理");
		
		String id=request.getParameter("id");
		String other_reason=request.getParameter("other_reason");
		String reason_select=request.getParameter("reason_select");
		result = req_bill_Service.req_reject_save(id,other_reason,reason_select);

		return result;
	}
	
	@RequestMapping(value = "/req_assign_detail_onload", method = { RequestMethod.GET })
	public String req_assign_detail_onload(HttpServletRequest request) {
		String g_id= request.getParameter("id");
		List<Req_bill> r = req_bill_Service.req_search(g_id);
		if(r.size()>0){
			//String s_tmp="req_bill_no:"+r.get(0).getReq_bill_no()+";req_title:"+r.get(0).getReq_title()+";req_type:"+r.get(0).getReq_type()+";req_dept:"+r.get(0).getReq_offer_dept()+";req_complete_date:"+r.get(0).getRequired_completion_date();
			String s_tmp=trans_2_json_assign_req( r.get(0));
			logger.info("req_assign_detail_onload:" + s_tmp);
			return s_tmp;	
		}else{
			return null;	
		}
				
	}
	
	@RequestMapping(value = "/req_modify_detail_onload", method = { RequestMethod.GET })
	public String req_modify_detail_onload(HttpServletRequest request) {
		String g_id= request.getParameter("req_id");
		List<Req_bill> r = req_bill_Service.req_search(g_id);
		if(r.size()>0){
			//String s_tmp="req_bill_no:"+r.get(0).getReq_bill_no()+";req_title:"+r.get(0).getReq_title()+";req_type:"+r.get(0).getReq_type()+";req_dept:"+r.get(0).getReq_offer_dept()+";req_complete_date:"+r.get(0).getRequired_completion_date();
			String s_tmp=trans_2_json_modify_req( r.get(0));
			logger.info("req_assign_detail_onload:" + s_tmp);
			return s_tmp;	
		}else{
			return null;	
		}
				
	}
	
	@RequestMapping(value = "/req_modify_detail_base_info_onload", method = { RequestMethod.GET })
	public String req_modify_detail_base_info_onload(HttpServletRequest request) {
		String g_id= request.getParameter("req_id");
		List<Req_bill> r = req_bill_Service.req_search(g_id);
		if(r.size()>0){
			//String s_tmp="req_bill_no:"+r.get(0).getReq_bill_no()+";req_title:"+r.get(0).getReq_title()+";req_type:"+r.get(0).getReq_type()+";req_dept:"+r.get(0).getReq_offer_dept()+";req_complete_date:"+r.get(0).getRequired_completion_date();
			String s_tmp=trans_2_json_modify_req_base_info(r.get(0));
			logger.info("req_assign_detail_onload:" + s_tmp);
			return s_tmp;	
		}else{
			return null;	
		}
				
	}
	
	@RequestMapping(value = "/req_modify_detail_team_info_onload", method = { RequestMethod.GET })
	public String req_modify_detail_team_info_onload(HttpServletRequest request) {
		logger.info("access /req/req_modify_detail_team_info_onload");
		
		String g_id= request.getParameter("req_id");
		logger.info("req_id ="+g_id);
		List<Req_bill> r = req_bill_Service.req_search(g_id);
		if(r!=null){
			//String s_tmp="req_bill_no:"+r.get(0).getReq_bill_no()+";req_title:"+r.get(0).getReq_title()+";req_type:"+r.get(0).getReq_type()+";req_dept:"+r.get(0).getReq_offer_dept()+";req_complete_date:"+r.get(0).getRequired_completion_date();
			String s_tmp=trans_2_json_modify_req_team_info(r.get(0));
			logger.info("req_assign_detail_onload:" + s_tmp);
			return s_tmp;	
		}else{
			return null;	
		}
	}
	
	
	@RequestMapping(value = "/req_modify_detail_team_info_save", method = { RequestMethod.POST })
	public boolean req_modify_detail_team_info_save(HttpServletRequest request) {
		boolean result=false;
		
		logger.info("进入 req_modify_detail_team_info_save 处理");
		
		String req_id=request.getParameter("req_id");
		String new_req_head=request.getParameter("req_head");
		String new_req_analyst=request.getParameter("req_analyst");
		String new_req_supervisor=request.getParameter("req_supervisor");
		Req_base_info r_base = req_bill_Service.search_req_base_info(req_id);
		String old_req_head=r_base.getReq_head();
		String old_req_analyst=r_base.getReq_analyst();
		String old_req_supervisor=r_base.getReq_supervisor();
		//req_head
		if (old_req_head==null){
			if(!new_req_head.equals("")){				
				//调入
				Map<String, Object> map = new HashMap<String, Object>();
				map.put("user_name", new_req_head);
				map.put("operate", "调入");
				map.put("remark", "");
				map.put("role", "需求负责人");
				map.put("req_id", req_id);
				result=req_bill_Service.add_req_team_info_log(map);
			}else{
				result=true;
			}
		}else{
			if(!new_req_head.equals(old_req_head)){
				//String[] old_head_array=old_req_head.split(",");
				//String[] new_head_array=new_req_head.split(",");
				String in_user="";
				in_user= get_in_users(new_req_head,old_req_head);
				//调入
				Map<String, Object> map = new HashMap<String, Object>();
				map.put("user_name", in_user);
				map.put("operate", "调入");
				map.put("remark", "");
				map.put("role", "需求负责人");
				map.put("req_id", req_id);
				result=req_bill_Service.add_req_team_info_log(map);
				//调出
				String out_user="";
				out_user= get_out_users(new_req_head,old_req_head);				
				//
				Map<String, Object> map2 = new HashMap<String, Object>();
				map2.put("user_name", out_user);
				map2.put("operate", "调出");
				map2.put("remark", "");
				map2.put("role", "需求负责人");
				map2.put("req_id", req_id);
				result=req_bill_Service.add_req_team_info_log(map2);			
			}else{
				result=true;
			}
		}
		//req_analyst
		if (old_req_analyst==null){
			if(!new_req_analyst.equals("")){
				//调入
				Map<String, Object> map = new HashMap<String, Object>();
				map.put("user_name", new_req_analyst);
				map.put("operate", "调入");
				map.put("remark", "");
				map.put("role", "需求负责人");
				map.put("req_id", req_id);
				result=req_bill_Service.add_req_team_info_log(map);
			}else{
				result=true;
			}
		}else{
			if(!new_req_analyst.equals(old_req_analyst)){
				String in_user="";
				in_user= get_in_users(new_req_analyst,old_req_analyst);
				if(in_user.length()>0){
				//调入
				Map<String, Object> map = new HashMap<String, Object>();
				map.put("user_name", in_user);
				map.put("operate", "调入");
				map.put("remark", "");
				map.put("role", "需求分析人");
				map.put("req_id", req_id);
				result=req_bill_Service.add_req_team_info_log(map);
				}
				//调出
				String out_user="";
				out_user= get_out_users(new_req_analyst,old_req_analyst);		
				if(out_user.length()>0){
				Map<String, Object> map2 = new HashMap<String, Object>();
				map2.put("user_name", out_user);
				map2.put("operate", "调出");
				map2.put("remark", "");
				map2.put("role", "需求分析人");
				map2.put("req_id", req_id);
				result=req_bill_Service.add_req_team_info_log(map2);			
				}
			}else{
				result=true;
			}
		}
		//req_supervisor
		if (old_req_supervisor==null){
			if(!new_req_supervisor.equals("")){
				//调入
				Map<String, Object> map = new HashMap<String, Object>();
				map.put("user_name", new_req_supervisor);
				map.put("operate", "调入");
				map.put("remark", "");
				map.put("role", "需求负责人");
				map.put("req_id", req_id);
				result=req_bill_Service.add_req_team_info_log(map);
			}else{
				result=true;
			}
		}else{
			if(!new_req_supervisor.equals(old_req_supervisor)){
				//调入
				String in_user="";
				in_user= get_in_users(new_req_supervisor,old_req_supervisor);
				if(in_user.length()>0){
					Map<String, Object> map = new HashMap<String, Object>();
					map.put("user_name", in_user);
					map.put("operate", "调入");
					map.put("remark", "");
					map.put("role", "需求监理人");
					map.put("req_id", req_id);
					result=req_bill_Service.add_req_team_info_log(map);
				}
				//调出				
				String out_user="";
				out_user= get_out_users(new_req_supervisor,old_req_supervisor);	
				if(out_user.length()>0){
					Map<String, Object> map2 = new HashMap<String, Object>();
					map2.put("user_name", out_user);
					map2.put("operate", "调出");
					map2.put("remark", "");
					map2.put("role", "需求监理人");
					map2.put("req_id", req_id);
					result=req_bill_Service.add_req_team_info_log(map2);		
				}
			}else{
				result=true;
			}
		}
		
		//update base_info
		Map<String, Object> map_base = new HashMap<String, Object>();
		map_base.put("req_head", new_req_head);
		map_base.put("req_supervisor", new_req_supervisor);
		map_base.put("req_analyst", new_req_analyst);
		map_base.put("req_id", req_id);
		boolean r_b=req_bill_Service.update_req_team_info(map_base);	
		result=result&&r_b;
		return result;
	}
	
	private String get_out_users(String new_req_head, String old_req_head) {
		String[] old_head_array=old_req_head.split(",");
		String[] new_head_array=new_req_head.split(",");
		String out_user="";
		for (int i = 0; i < old_head_array.length; i++) {
			boolean is_out=true;
			String com=old_head_array[i];
			for (int j = 0; j < new_head_array.length; j++) {
				if(com.equals(new_head_array[j])){
					is_out=false;
				}
			}					
			if(is_out){
				if(out_user.length()>1){
					out_user=out_user+","+com;
				}else{
					out_user=out_user+""+com;
				}
			}
		}
		return out_user;
	}

	private String get_in_users(String new_req_head, String old_req_head) {
		
		String[] old_head_array=old_req_head.split(",");
		String[] new_head_array=new_req_head.split(",");
		String in_user="";
		for (int i = 0; i < new_head_array.length; i++) {
			boolean is_in=true;
			String com=new_head_array[i];
			for (int j = 0; j < old_head_array.length; j++) {
				if(com.equals(old_head_array[j])){
					is_in=false;
				}
			}					
			if(is_in){
				if(in_user.length()>1){
					in_user=in_user+","+com;
				}else{
					in_user=in_user+""+com;
				}
			}
		}
		return in_user;
	}

	@RequestMapping(value = "/req_modify_detail_team_info_grid", method = { RequestMethod.GET })
	public String req_modify_detail_team_info_grid(HttpServletRequest request) {
		logger.info("access /req/req_modify_detail_team_info_grid");		
		String g_id= request.getParameter("req_id");
		logger.info("req_id ="+g_id);
		Req_base_info r = req_bill_Service.search_req_base_info(g_id);
		if(r!=null){
			//String s_tmp="req_bill_no:"+r.get(0).getReq_bill_no()+";req_title:"+r.get(0).getReq_title()+";req_type:"+r.get(0).getReq_type()+";req_dept:"+r.get(0).getReq_offer_dept()+";req_complete_date:"+r.get(0).getRequired_completion_date();
			String s_tmp=trans_2_json_req_modify_detail_team_info_grid(r);
			logger.info("req_modify_detail_team_info_grid :" + s_tmp);
			return s_tmp;	
		}else{
			return null;	
		}
	}	


	private String trans_2_json_req_modify_detail_team_info_grid(Req_base_info r) {
		List<Req_team_info_log> obj=req_bill_Service.search_req_team_info_log(r.getReq_id());
		String r_s="";
		if(obj!=null){
		String r_start="{rows:[";		
		String r_end="]}";
		String r_content="";
		
		for (int i = 0; i < obj.size(); i++) {
			Req_team_info_log element = obj.get(i);
			String tmp_start="{ id:"+(i+1)+",data:[";
			String tmp_end="]}";
			if((i+1)<obj.size()){
				tmp_end=tmp_end+",";
			}
			
			//String tmp_content="'0',";
			String tmp_content="";
			SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			String date_tmp= sdf.format(element.getOperate_time());			

			tmp_content=tmp_content+"'"+date_tmp+"',";
			tmp_content=tmp_content+"'"+element.getUser_name()+"',";
			tmp_content=tmp_content+"'"+element.getOperate()+"',";
			tmp_content=tmp_content+"'"+element.getRole()+"',";
			
			r_content=r_content+tmp_start+tmp_content+tmp_end;
		}
		r_s=r_start+r_content+r_end;
		logger.info("trans_2_json :" + r_s);
		}
		return r_s;
		
	}

	private String trans_2_json_modify_req_team_info(Req_bill req_bill) {
		List<User> list_u=userService.getAllUserList();
		String json_all_user=trans_all_user_2_json(list_u);
	
		Req_base_info req_base_info=req_bill_Service.search_req_base_info(req_bill.getId().toString());
		String json_req_head=trans_json_for_req_head(list_u,req_base_info);					
		
		
		
		String json_req_analyst_filter_user="";
		String json_req_analyst="";
		String json_req_analyst_value="";
			if(req_base_info!=null){
				json_req_analyst=req_base_info.getReq_analyst();
				String[] tmp1=json_req_analyst.split(",");
				for (int i = 0; i < tmp1.length; i++) {
					if(i==tmp1.length){
						json_req_analyst_value=json_req_analyst_value+"{value : '"+tmp1[i]+"',text:'"+tmp1[i]+"'}";
					}
					else{
						json_req_analyst_value=json_req_analyst_value+"{value : '"+tmp1[i]+"',text:'"+tmp1[i]+"'},";
					}
				}
				json_req_analyst_filter_user=filter_user_2_json(list_u,json_req_analyst);
			}else{
				json_req_analyst_filter_user=json_all_user;
			}
			
			
			
		String json_req_supervisor_filter_user="";			
		String json_req_supervisor="";
		String json_req_supervisor_value="";
			if(req_base_info!=null){
				json_req_supervisor=req_base_info.getReq_supervisor();
				if(json_req_supervisor==null||json_req_supervisor.equals("")){
					json_req_supervisor="";
					json_req_supervisor_filter_user=json_all_user;
				}else{
					String[] tmp2=json_req_supervisor.split(",");
					for (int i = 0; i < tmp2.length; i++) {
						if(i==tmp2.length){
							json_req_supervisor_value=json_req_supervisor_value+"{value : '"+tmp2[i]+"',text:'"+tmp2[i]+"'}";
						}
						else{
							json_req_supervisor_value=json_req_supervisor_value+"{value : '"+tmp2[i]+"',text:'"+tmp2[i]+"'},";
						}	
					}
					json_req_supervisor_filter_user=filter_user_2_json(list_u,json_req_supervisor);
				}				
			}else{
				json_req_supervisor_filter_user=json_all_user;
			}
			
		String r_start="["
						+"{type:'block',list:["
							+"{type : 'hidden',name : 'req_id',label : '需求ID',labelWidth:'70',position:'label-left', disabled:'true',value:'"+req_bill.getId()+"'}"
						+"]},"
						+"{type:'block',list:["
						 	+"{type: 'combo', label: '需求负责人', name: 'req_head', width:100,required:'true',options:["
						 				+json_req_head
						 			+"]"
							+ "},"
						/*	+ "{type: 'fieldset', label: '需求负责人',   list:["
											+"{type:'multiselect', name:'req_head', size:4, options:["
												+"{value : '"+req_base_info.getReq_head()+"',text:'"+req_base_info.getReq_head()+"'}"
											+"]},"
											+"{type : 'newcolumn'},"
											+"{type:'block',list:["
												+"{type: 'button', name: 'add1', value: '>>',width:30, offsetTop: 10},"
												+"{type: 'button', name: 'remove1', width:30,value:'<<'}"
											+"]},"
											+"{type : 'newcolumn'},"
											+"{type:'multiselect', name:'req_head_all', size:5, options:["						
												+json_all_user
											+"]}"
										+"]"
								+ "},"
								
							+"{type : 'newcolumn'},"	
							+"{type : 'input',name : 'req_supervisor',label : '需求分析人',inputWidth:'140',position:'label-left',required:'true'},"
							+"{type : 'newcolumn'},"
							+"{type: 'combo', name: 'req_head', width:100,options:["
			 							+json_req_head
			 						+"]"
			 				+ "},"*/
							+"{type : 'newcolumn'},"
							+ "{type: 'block', offsetLeft:10, list:["
										+"{type:'multiselect',label: '需求分析人', position: 'label-top', name:'req_analyst', size:5,width:80, options:["
										    +json_req_analyst_value
										+"]},"
										+"{type : 'newcolumn'},"
										+"{type:'block',list:["
											+"{type: 'button', name: 'add2', value: '>>', width:30,offsetTop: 30},"
											+"{type: 'button', name: 'remove2', width:30,value:'<<'}"
										+"]},"
										+"{type : 'newcolumn'},"
										+"{type:'multiselect', name:'req_analyst_all', size:5, offsetTop: 30,width:80,options:["						
											+json_req_analyst_filter_user
										+"]}"
									+"]"
							+ "},"
							+"{type : 'newcolumn'},"
							+ "{type: 'block', offsetLeft:10, list:["
									+"{type:'multiselect', label: '需求监理人',position: 'label-top',name:'req_supervisor', size:5, width:80,options:["
										+json_req_supervisor_value
									+"]},"
									+"{type : 'newcolumn'},"
									+"{type:'block',list:["
										+"{type: 'button', name: 'add3', value: '>>', width:30,offsetTop: 30},"
										+"{type: 'button', name: 'remove3', width:30,value:'<<'}"
									+"]},"
									+"{type : 'newcolumn'},"
									+"{type:'multiselect', name:'req_supervisor_all', size:5,width:80, offsetTop: 30,options:["						
										+json_req_supervisor_filter_user
									+"]}"
								+"]"
							+ "}"
					+"]},"
					+"{type:'block',list:["
						+"{type : 'button',name : 'team_info_save_btn',value : '保存修改'}"
					+"]},"
					+"{type:'block',list:["
							+"{type : 'label',name : 'display_label',label: '项目成员变动情况'}"													
					+"]}"			
				+"]";
		String r_s=r_start;
		logger.info("retrun team info :" + r_start);
		return r_s;
	}

	private String filter_user_2_json(List<User> list_u, String json_req_analyst) {
		String json_s="";
		
		String[] s_array=json_req_analyst.split(",");
		for (int i = 0; i < list_u.size(); i++) {
			User u = list_u.get(i);
			String tmp=u.getName();
			//判断是否与旧值相同
			boolean check_r=false;
			for (int j = 0; j < s_array.length; j++) {
				if(tmp.equals(s_array[j])){	
					check_r=true;
				}
			}
			if(check_r){
				//相同不加入
			}else{
				//不相周加入
				if(i==list_u.size()){
					json_s=json_s+"{value : '"+tmp+"',text:'"+tmp+"'}";
				}else{
					json_s=json_s+"{value : '"+tmp+"',text:'"+tmp+"'},";
				}
			}	
			
		}		
		
		return json_s;
	}

	private String trans_json_for_req_head(List<User> list_u, Req_base_info req_base_info) {
		String json_s="{value : '',text:''},";
		if(req_base_info!=null){
			String tmp_head=req_base_info.getReq_head();
			String[] s_array=tmp_head.split(",");
			for (int i = 0; i < list_u.size(); i++) {
				User u = list_u.get(i);
				String tmp=u.getName();
				if(i==list_u.size()){
					for (int j = 0; j < s_array.length; j++) {
						if(tmp.equals(s_array[j])){
							json_s=json_s+"{value : '"+tmp+"',text:'"+tmp+"', selected: true}";
						}else{
							json_s=json_s+"{value : '"+tmp+"',text:'"+tmp+"'}";
						}
					}
					
				}else{
					for (int j = 0; j < s_array.length; j++) {
						if(tmp.equals(tmp_head)){
							json_s=json_s+"{value : '"+tmp+"',text:'"+tmp+"', selected: true},";
						}else{
							json_s=json_s+"{value : '"+tmp+"',text:'"+tmp+"'},";
						}
					}
				}
			}		
		}else{
			json_s="{value : '',text:''}";
		}
		
		return json_s;
	}

	private String trans_all_user_2_json(List<User> list_u) {
		String json_s="";
		for (int i = 0; i < list_u.size(); i++) {
			User u = list_u.get(i);
			String tmp=u.getName();
			if(i==list_u.size()){
				json_s=json_s+"{value : '"+tmp+"',text:'"+tmp+"'}";
			}else{
				json_s=json_s+"{value : '"+tmp+"',text:'"+tmp+"'},";
			}
		}		
		
		return json_s;
	}
	@RequestMapping(value = "/maintaining_req_search_my", method = { RequestMethod.GET })
	public String maintaining_req_search_my(HttpServletRequest request) {
		// List<Req_bill> result=false;
		String g_p = request.getParameter("params");
		String[] s_array = g_p.split(",",9);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("req_titile", s_array[0]);
		map.put("accept_date", s_array[1]);
		map.put("req_bill_no", s_array[2]);
		map.put("req_status", s_array[3]);
		map.put("req_type", s_array[4]);
		map.put("req_offer_dept", s_array[5]);
		map.put("deffect_no", s_array[6]);
		map.put("current_user", s_array[7]);
					
		List<Req_bill> r = req_bill_Service.maintaining_req_search_my(map);
		
		if(r!=null){
		
			//String s2=trans_2_json(r);		
			//return s2;
			String value0="0";
			String s2="";
			if(s_array[8].equals(value0)){
				 s2=trans_2_json(r);								
			}else{
				List<Req_bill> r2=new ArrayList<Req_bill>();
				for (Req_bill req_bill : r) {
					String g_req_id=String.valueOf(req_bill.getId());
					List<Req_workload_info> list=req_bill_Service.search_req_workload_info(g_req_id);
					if(list!=null){					
						boolean is_add=false;
						Req_base_info req_basee_info=req_bill_Service.search_req_base_info(g_req_id);
						float g_plan_workload_summ=req_basee_info.getReq_workload();
						float count_actual_workload=0;
						for (Req_workload_info req_workload_info : list) {
							String getActual_workload= req_workload_info.getActual_workload();
							String getPlan_workload= req_workload_info.getPlan_workload();
							if(getActual_workload!=null){
								String check_value="";
								if(!getActual_workload.equals(check_value)){
									float f1=Float.valueOf(getActual_workload);
									count_actual_workload=count_actual_workload+f1;
									
									if(getPlan_workload!=null){
										if(!getPlan_workload.equals(check_value)){
											float f2=Float.valueOf(getPlan_workload);
											if(f1>f2){
												is_add=true;
											}
										}
									}
								}
							}						
						}
						if (count_actual_workload>g_plan_workload_summ){
							is_add=true;
						}
						
						if(is_add){
							r2.add(req_bill);
						}
					}
				}
				 s2=trans_2_json(r2);	
			}			
			return s2;
			
			
		}else{
			return null;
		}		
	}
	
	@RequestMapping(value = "/maintaining_req_search", method = { RequestMethod.GET })
	public String maintaining_req_search(HttpServletRequest request) {
		// List<Req_bill> result=false;
		String g_p = request.getParameter("params");
		String[] s_array = g_p.split(",",8);
		Map<String, Object> map = new HashMap<String, Object>();
		if(!s_array[0].equals("")){
			map.put("req_titile", s_array[0]);
			}
		if(!s_array[1].equals("null")){
			map.put("accept_date", s_array[1]);
			}
		if(!s_array[2].equals("")){
			map.put("req_bill_no", s_array[2]);
		}						
		if(!s_array[3].equals("")){
			map.put("req_status", s_array[3]);
		}			
		if(!s_array[4].equals("")){
			map.put("req_type", s_array[4]);
		}
		if(!s_array[5].equals("")){
			map.put("req_offer_dept", s_array[5]);
		}
		if(!s_array[6].equals("")){
			String tmp=s_array[6];
			tmp=tmp.replace(">", "#");
			map.put("deffect_no", tmp);									
		}
		
		List<Req_bill> r = req_bill_Service.maintaining_req_search(map);
		
		
		if(r!=null){
			String value0="0";
			String s2="";
			if(s_array[7].equals(value0)){
				 s2=trans_2_json(r);								
			}else{
				List<Req_bill> r2=new ArrayList<Req_bill>();
				for (Req_bill req_bill : r) {
					String g_req_id=String.valueOf(req_bill.getId());
					List<Req_workload_info> list=req_bill_Service.search_req_workload_info(g_req_id);
					if(list!=null){					
						boolean is_add=false;
						Req_base_info req_basee_info=req_bill_Service.search_req_base_info(g_req_id);
						float g_plan_workload_summ=req_basee_info.getReq_workload();
						float count_actual_workload=0;
						for (Req_workload_info req_workload_info : list) {
							String getActual_workload= req_workload_info.getActual_workload();
							String getPlan_workload= req_workload_info.getPlan_workload();
							if(getActual_workload!=null){
								String check_value="";
								if(!getActual_workload.equals(check_value)){
									float f1=Float.valueOf(getActual_workload);
									count_actual_workload=count_actual_workload+f1;
									
									if(getPlan_workload!=null){
										if(!getPlan_workload.equals(check_value)){
											float f2=Float.valueOf(getPlan_workload);
											if(f1>f2){
												is_add=true;
											}
										}
									}
								}
							}						
						}
						if (count_actual_workload>g_plan_workload_summ){
							is_add=true;
						}
						
						if(is_add){
							r2.add(req_bill);
						}
					}
				}
				 s2=trans_2_json(r2);	
			}			
			return s2;
		}else{
			return null;
		}		
	}
	
	// @RequestMapping("/req_search",method=)
	@RequestMapping(value = "/req_search", method = { RequestMethod.GET })
	public String req_search(HttpServletRequest request) {
		// List<Req_bill> result=false;
		String g_p = request.getParameter("params");
		String[] s_array = g_p.split(",");
		Map<String, Object> map = new HashMap<String, Object>();
		if (s_array.length > 0) {
			map.put("req_titile", s_array[0]);
			if (s_array.length > 1) {
				map.put("req_type", s_array[1]);
				if (s_array.length > 2) {
					map.put("offer_dept", s_array[2]);
					if (s_array.length > 3) {
						map.put("deffect_no", s_array[3]);
					}
				}
			}
		}
		List<Req_bill> r = req_bill_Service.req_search(map);
		
		if(r.size()>0){
			//return r;
			String s2=trans_2_json(r);
			//String s="{rows:[ { id:1,data:[ '0','5','req_no','req_typeJohn Grisham','12.99','1','05/01/1998'] },{ id:2,data:[ '1','2','req_no','req_typeJohn Grisham','12.99','1','05/01/1998'] }]}";
			//String s="{rows:[ { id:1,data:[ '0','5','req_no','req_typeJohn Grisham','12.99','1','05/01/1998'] }]}";
			return s2;
		}else{
			return null;
		}		
	}
	
	
	@RequestMapping(value = "/req_search_for_assign", method = { RequestMethod.GET })
	public String req_search_for_assign(HttpServletRequest request) {
		// List<Req_bill> result=false;
		String g_p = request.getParameter("params");
		String[] s_array = g_p.split(",",5);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("req_titile", s_array[0]);
		map.put("req_type", s_array[1]);
		map.put("offer_dept", s_array[2]);
		map.put("deffect_no", s_array[3]);
		map.put("req_bill_no", s_array[4]);
		
		List<Req_bill> r = req_bill_Service.req_search_for_assign(map);
		
		if(r!=null){
			//return r;
			String s2=trans_2_json(r);
			//String s="{rows:[ { id:1,data:[ '0','5','req_no','req_typeJohn Grisham','12.99','1','05/01/1998'] },{ id:2,data:[ '1','2','req_no','req_typeJohn Grisham','12.99','1','05/01/1998'] }]}";
			//String s="{rows:[ { id:1,data:[ '0','5','req_no','req_typeJohn Grisham','12.99','1','05/01/1998'] }]}";
			return s2;
		}else{
			return null;
		}		
	}

	private String trans_2_json(List<Req_bill> obj) {
		String r_start="{rows:[";		
		String r_end="]}";
		String r_content="";
		
		for (int i = 0; i < obj.size(); i++) {
			Req_bill element = obj.get(i);
			String tmp_start="{ id:"+(i+1)+",data:[";
			String tmp_end="]}";
			if((i+1)<obj.size()){
				tmp_end=tmp_end+",";
			}
			
			String tmp_content="'0',";
			tmp_content=tmp_content+"'"+element.getId()+"',";
			tmp_content=tmp_content+"'"+element.getReq_bill_no()+"',";
			tmp_content=tmp_content+"'"+element.getReq_status()+"',";
			tmp_content=tmp_content+"'"+element.getReq_title()+"',";
			tmp_content=tmp_content+"'"+element.getReq_type()+"',";			
			tmp_content=tmp_content+"'"+element.getReq_offer_dept()+"',";
			if(element.getRequired_completion_date()==null){
				tmp_content=tmp_content+"'',";
			}else{				
				SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
				
				tmp_content=tmp_content+"'"+sdf.format(element.getRequired_completion_date())+"',";
			}
			
			tmp_content=tmp_content+"'"+element.getDeffect_no()+"'";
			
			r_content=r_content+tmp_start+tmp_content+tmp_end;
		}
		String r_s=r_start+r_content+r_end;
		logger.info("trans_2_json :" + r_s);
		return r_s;
	}
	
	private String trans_2_json_assign_req(Req_bill obj) {
		Date d =obj.getRequired_completion_date();
		String d_s="";
		if (d==null){
			d_s="";
		}else{
			SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
			d_s= sdf.format(d);
		}
		List<User> list_u=userService.getAllUserList();
		String json_all_user=trans_all_user_2_json(list_u);		
		String json_req_head="{text: '', value: ''},"+json_all_user;
		String old_att="";
		List<Attachment> att_list=att_Service.search_old_atts_by_req_id(obj.getId());
		if (att_list != null) {
			for (int i = 0; i < att_list.size(); i++) {
				Attachment att_tmp = att_list.get(i);
				if (i==att_list.size()) {
					old_att=old_att+"{type:'block',list:["
											+"{type : 'label', name:'"+att_tmp.getAtt_file_name()+"',labelWidth:'200', label:'"+att_tmp.getAtt_file_name()+"'},"
											+"{type : 'newcolumn'},"
											+"{type : 'button',name : 'download_"+att_tmp.getId()+"',value : '下载'}"
									+"]}";	
				} else {
					old_att=old_att+"{type:'block',list:["
											+"{type : 'label', name:'"+att_tmp.getAtt_file_name()+"',labelWidth:'200', label:'"+att_tmp.getAtt_file_name()+"'},"
											+"{type : 'newcolumn'},"
											+"{type : 'button',name : 'download_"+att_tmp.getId()+"',value : '下载'}"
									+"]},";	

				}
				
			}
		}
		
		Req_base_info req_base_info=req_bill_Service.search_req_base_info(String.valueOf(obj.getId()));
		String json_req_analyst_value="";
		String json_req_analyst="";
		String json_req_analyst_filter_user="";
		if(req_base_info!=null){
			json_req_analyst=req_base_info.getReq_analyst();
			String[] tmp1=json_req_analyst.split(",");
			for (int i = 0; i < tmp1.length; i++) {
				if(i==tmp1.length){
					json_req_analyst_value=json_req_analyst_value+"{value : '"+tmp1[i]+"',text:'"+tmp1[i]+"'}";
				}
				else{
					json_req_analyst_value=json_req_analyst_value+"{value : '"+tmp1[i]+"',text:'"+tmp1[i]+"'},";
				}
			}
			json_req_analyst_filter_user=filter_user_2_json(list_u,json_req_analyst);
		}else{
			json_req_analyst_filter_user=json_all_user;
		}
		
		
		
	String json_req_supervisor_filter_user="";			
	String json_req_supervisor="";
	String json_req_supervisor_value="";
		if(req_base_info!=null){
			json_req_supervisor=req_base_info.getReq_supervisor();
			if(json_req_supervisor==null||json_req_supervisor.equals("")){
				json_req_supervisor="";
				json_req_supervisor_filter_user=json_all_user;
			}else{
				String[] tmp2=json_req_supervisor.split(",");
				for (int i = 0; i < tmp2.length; i++) {
					if(i==tmp2.length){
						json_req_supervisor_value=json_req_supervisor_value+"{value : '"+tmp2[i]+"',text:'"+tmp2[i]+"'}";
					}
					else{
						json_req_supervisor_value=json_req_supervisor_value+"{value : '"+tmp2[i]+"',text:'"+tmp2[i]+"'},";
					}	
				}
				json_req_supervisor_filter_user=filter_user_2_json(list_u,json_req_supervisor);
			}				
		}else{
			json_req_supervisor_filter_user=json_all_user;
		}
		
		
		String r_start="["
						+ "{type: 'fieldset', label: '分配需求',  list:["
										+"{type:'block',list:["
											+"{type : 'hidden',name : 'req_id',label : '需求ID',labelWidth:'70',position:'label-left', disabled:'true',value:'"+obj.getId()+"'}"
										+"]},"
										+"{type:'block',list:["
												+"{type : 'input',name : 'req_bill_no',label : '需求编号',inputWidth:'150',labelWidth:'70',position:'label-left', disabled:'true',value:'"+obj.getReq_bill_no()+"'},"
												+"{type : 'newcolumn'},"
												+"{type : 'input',name : 'req_status',label : '需求状态',inputWidth:'150',labelWidth:'70',position:'label-left',offsetLeft:'25', disabled:'true',value:'"+obj.getReq_status()+"'}"
											+"]},"
										+"{type:'block',list:["
											+"{type : 'input',name : 'req_title',label : '需求主题',inputWidth:'600',labelWidth:'70',position:'label-left', disabled:'true',value:'"+obj.getReq_title()+"'}"
										+"]},"
										+"{type:'block',list:["
											+"{type : 'input',name : 'req_type',label : '需求类型',inputWidth:'150',labelWidth:'70',position:'label-left', disabled:'true',value:'"+obj.getReq_type()+"'},"
											+"{type : 'newcolumn'},"
											+"{type : 'input',name : 'req_offer_dept',label : '需求提出部门',inputWidth:'150',position:'label-left', disabled:'true',offsetLeft:'25',value:'"+obj.getReq_offer_dept()+"'},"
											+"{type : 'newcolumn'},"
											+"{type : 'input',name : 'required_completion_date',label : '要求完成日期',inputWidth:'150',position:'label-left', disabled:'true',offsetLeft:'25',value:'"+d_s+"'}"
										+"]},"
										+"{type:'block',list:["
											+"{type : 'select',name : 'req_orientation',label : '需求定位',inputWidth:'150', required:'true',options:["
													+"{text: '', value: ''},"
													+"{text: '项目需求', value: '项目需求'},"
													+"{text: '功能需求', value: '功能需求'},"
													+"{text: '参数配置', value: '参数配置'},"
													+"{text: '缺陷转需求',value: '缺陷转需求'},"
													+"{text: '其他',value: '其他'}"
											+ "]},"
											+"{type : 'newcolumn'},"
											//+"{type : 'input',name : 'req_head',label : '需求负责人',inputWidth:'150',position:'label-left', required:'true'},"
											+"{type : 'calendar',name : 'req_plan_date',label : '计划完成日',position:'label-left', offsetLeft:'25',required:'true'},"
											+"{type : 'newcolumn'},"
											//+"{type : 'input',name : 'req_analyst',label : '需求分析人',inputWidth:'150',position:'label-left', required:'true',offsetLeft:'25'}"
											+"{type : 'select',name : 'req_difficult',label : '需求难度',inputWidth:'150', required:'true',offsetLeft:'25',options:["
												+"{text: '', value: ''},"
												+"{text: '大', value: '大'},"
												+"{text: '中', value: '中'},"
												+"{text: '小', value: '小'}"
											+ "]}"
										+"]},"
										+"{type:'block',list:["
											//+"{type : 'input',name : 'req_supervisor',label : '需求监理人',inputWidth:'140',position:'label-left',required:'true'},"
											+"{type: 'combo', label: '需求负责人', name: 'req_head', inputWidth:'150',required:'true',options:["
																+json_req_head
														+"]"
													+ "},"
											+"{type : 'newcolumn'},"
											+"{type : 'input',name : 'req_workload',label : '需求分析工作量',inputWidth:'150',position:'label-left',validate:'check_workload', required:'true',offsetLeft:'25'},"
											+"{type : 'newcolumn'},"
											+"{type : 'input',name : 'req_workload_label',label : '人天',inputWidth:'0',position:'label-left'}"
										+"]},"
										+"{type:'block',list:["												
											+ "{type: 'block', offsetLeft:10, list:["
												+"{type:'multiselect',label: '需求分析人', position: 'label-top', required:'true',name:'req_analyst', size:5,width:80, options:["
												    +json_req_analyst_value
												+"]},"
												+"{type : 'newcolumn'},"
												+"{type:'block',list:["
													+"{type: 'button', name: 'add2', value: '>>', width:30,offsetTop: 30},"
													+"{type: 'button', name: 'remove2', width:30,value:'<<'}"
												+"]},"
												+"{type : 'newcolumn'},"
														+"{type:'multiselect', name:'req_analyst_all', size:5, offsetTop: 30,width:80,options:["						
															+json_req_analyst_filter_user
														+"]}"
														+"]"
												+ "},"
												+"{type : 'newcolumn'},"
												+ "{type: 'block', offsetLeft:10, list:["
														+"{type:'multiselect', label: '需求监理人',position: 'label-top',name:'req_supervisor', size:5, width:80,options:["
															+json_req_supervisor_value
														+"]},"
														+"{type : 'newcolumn'},"
														+"{type:'block',list:["
															+"{type: 'button', name: 'add3', value: '>>', width:30,offsetTop: 30},"
															+"{type: 'button', name: 'remove3', width:30,value:'<<'}"
														+"]},"
														+"{type : 'newcolumn'},"
														+"{type:'multiselect', name:'req_supervisor_all', size:5,width:80, offsetTop: 30,options:["						
															+json_req_supervisor_filter_user
														+"]}"
													+"]"
												+ "}"
										+"]},"
										+"{type:'block',list:["
											+"{type : 'editor',name : 'req_introduction', label : '方案简介',position:'label-top', inputWidth:'800',inputHeight:'200'},"
											+"{type : 'editor',name : 'req_remark',label : '备注说明',position:'label-top', inputWidth:'800', inputHeight:'200'}"										
										+"]},"										
										+ "{type: 'fieldset', label: '接收时已上传附件',  list:["
											+old_att												
										+"]},"		
										+"{type:'fieldset',label:'附件',list:["
											+"{type : 'label', name:'att_label', label:'上传文件最大值: 100 Mb'},"
											+"{type:'upload', name:'myFiles', inputWidth:'400', titleText:'拖拽文件到此区域或点击选择文件上传', url:'/attachment/upload', _swfLogs:'enabled',  autoStart:'true', swfPath:'/common/uploader.swf',  swfUrl:'attachment/upload'}"
										+"]},"												
										+"{type:'block',list:["
											+"{type : 'input',name : 'att_group_id',label : 'att_group_id',inputWidth:'150',position:'label-left', hidden:'true',offsetLeft:'25'},"
											+"{type : 'input',name : 'att_id',label : 'att_id',inputWidth:'150',position:'label-left', hidden:'true', offsetLeft:'25'}"										
										+"]},"										
										+"{type:'block',list:["
											+"{type : 'button',name : 'assign_btn1',value : '分配需求'},"
											+"{type : 'newcolumn'},"
											+"{type : 'button',name : 'assign_btn2',value : '退回'}"										
										+"]}"											
										//+"{type:'block',list:["
										//	+"{type : 'input',name : 'req_title',label : '需求主题',labelWidth:'70', inputWidth='700',position:'label-left', disabled:'true',value:'"+obj.getReq_title()+"'}"
										//+"]}"
										
									+"]"
							+ "}"
						+"]";
		String r_s=r_start;
		return r_s;
	
	}
	
	private String trans_2_json_modify_req(Req_bill obj) {
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
		Date d =obj.getRequired_completion_date();
		String d_s="";
		if (d==null){
			d_s="";
		}else{
			
			d_s= sdf.format(d);
		}
		String req_assign_date="";
		Req_base_info req_base_info=req_bill_Service.search_req_base_info(String.valueOf(obj.getId()));
		if(req_base_info!=null){
			req_assign_date=sdf.format(req_base_info.getCreate_time());
		}
		String r_start="["
						+ "{type: 'fieldset', label: '维护需求',  list:["
										+"{type:'block',list:["
											+"{type : 'hidden',name : 'id',label : '需求ID',labelWidth:'70',position:'label-left', disabled:'true',value:'"+obj.getReq_bill_no()+"'}"
										+"]},"
										+"{type:'block',list:["
												+"{type : 'input',name : 'req_bill_no',label : '需求编号',inputWidth:'150',labelWidth:'70',position:'label-left', disabled:'true',value:'"+obj.getReq_bill_no()+"'},"
												+"{type : 'newcolumn'},"
												+"{type : 'input',name : 'deffect_no',label : '缺陷编号',inputWidth:'150',labelWidth:'70',position:'label-left', disabled:'true',value:'"+obj.getDeffect_no()+"'},"
												//+"{type : 'input',name : 'req_status',label : '需求状态',inputWidth:'150',labelWidth:'70',position:'label-left', disabled:'true',value:'"+obj.getReq_status()+"'}"
											+"]},"
										+"{type:'block',list:["
												+"{type : 'input',name : 'req_title',label : '需求主题',inputWidth:'600',labelWidth:'70',position:'label-left', disabled:'true',value:'"+obj.getReq_title()+"'}"
										+"]},"
										+"{type:'block',list:["
											+"{type : 'input',name : 'req_type',label : '需求类型',inputWidth:'150',labelWidth:'70',position:'label-left', disabled:'true',value:'"+obj.getReq_type()+"'},"
											+"{type : 'newcolumn'},"
											+"{type : 'input',name : 'req_offer_dept',label : '需求提出部门',inputWidth:'150',position:'label-left', disabled:'true',value:'"+obj.getReq_offer_dept()+"'},"
											+"{type : 'newcolumn'},"
											+"{type : 'input',name : 'required_completion_date',label : '要求完成时间',inputWidth:'150',position:'label-left', disabled:'true',value:'"+d_s+"'}"
										+"]},"
										
										+"{type:'block',list:["
											+"{type : 'input',name : 'req_receive_date',label : '需求接收时间',inputWidth:'130',labelWidth:'90',position:'label-left', disabled:'true',value:'"+sdf.format(obj.getAccept_date())+"'},"
											+"{type : 'newcolumn'},"
											+"{type : 'input',name : 'req_assign_date',label : '需求分配时间',inputWidth:'150',labelWidth:'90',position:'label-left', disabled:'true',value:'"+req_assign_date+"'},"																			
										+"]}"		
										/*+"{type:'block',list:["
											+"{type : 'select',name : 'req_difficult',label : '需求定位',inputWidth:'150', required:'true',options:["
													+"{text: '', value: ''},"
													+"{text: '项目需求', value: '项目需求'},"
													+"{text: '功能需求', value: '功能需求'},"
													+"{text: '参数配置', value: '参数配置'},"
													+"{text: '缺陷转需求',value: '缺陷转需求'},"
													+"{text: '其他',value: '其他'}"
											+ "]},"
											+"{type : 'newcolumn'},"
											+"{type : 'input',name : 'req_head',label : '需求负责人',inputWidth:'150',position:'label-left', required:'true'},"
											+"{type : 'newcolumn'},"
											+"{type : 'input',name : 'req_analyst',label : '需求分析人',inputWidth:'150',position:'label-left', required:'true',offsetLeft:'25'}"
										+"]},"
										+"{type:'block',list:["
											+"{type : 'input',name : 'req_supervisor',label : '需求监理人',inputWidth:'140',position:'label-left',required:'true'},"
											+"{type : 'newcolumn'},"
											+"{type : 'select',name : 'req_difficult',label : '需求难度',inputWidth:'150', required:'true',options:["
													+"{text: '', value: ''},"
													+"{text: '大', value: '大'},"
													+"{text: '中', value: '中'},"
													+"{text: '小', value: '小'}"
											+ "]},"
											+"{type : 'newcolumn'},"
											+"{type : 'input',name : 'req_workload',label : '需求分析工作量',inputWidth:'50',position:'label-left', required:'true',offsetLeft:'25'}"
										+"]},"
										+"{type:'block',list:["
												+"{type : 'calendar',name : 'req_plan_date',label : '计划完成日',position:'label-left', required:'true'}"
										+"]},"
										+"{type:'block',list:["
											+"{type : 'editor',name : 'req_introduction',label : '方案简介',position:'label-top', required:'true',inputWidth:'800', inputHeight:'200'},"
											+"{type : 'editor',name : 'req_remark',label : '备注说明',position:'label-top', required:'true',inputWidth:'800', inputHeight:'200'}"										
										+"]},"
										+"{type:'block',list:["
											+"{type : 'button',name : 'assign_btn1',value : '分配需求'},"
											+"{type : 'newcolumn'},"
											+"{type : 'button',name : 'assign_btn2',value : '退回'}"										
										+"]}"											
										//+"{type:'block',list:["
										//	+"{type : 'input',name : 'req_title',label : '需求主题',labelWidth:'70', inputWidth='700',position:'label-left', disabled:'true',value:'"+obj.getReq_title()+"'}"
										//+"]}"
										 
										 */
									+"]"
							+ "}"
						+"]";
		String r_s=r_start;
		return r_s;	
	}
	
	private String trans_2_json_modify_req_base_info(Req_bill obj) {
		Date d =obj.getRequired_completion_date();
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
		String d_s="";
		if (d==null){
			d_s="";
		}else{
			
			d_s= sdf.format(d);
		}
		List<Req_base_info> g_r_base_info=req_bill_Service.req_base_info_search(String.valueOf(obj.getId()));
		Req_base_info req_base_info_obj=null;
		if(g_r_base_info==null){
			req_base_info_obj=new Req_base_info();
		}else{
			 req_base_info_obj=g_r_base_info.get(0);
		}
		
		String g_Technical_director="";
		if(req_base_info_obj.getTechnical_director()!=null){
			g_Technical_director=req_base_info_obj.getTechnical_director();
		}
		String g_plan_date="";
		if(req_base_info_obj.getReq_plan_date()!=null){
			g_plan_date=sdf.format(req_base_info_obj.getReq_plan_date());
		}
		String g_act_date="";
		if(req_base_info_obj.getActual_finish_date()!=null){
			g_act_date=sdf.format(req_base_info_obj.getActual_finish_date());
		}
		String g_act_workload="";
		double get_workload=req_bill_Service.search_a_req_act_workload(obj.getId());
		if( get_workload >0){
			g_act_workload=String.valueOf(get_workload);
		}
		
		String old_att="";
		List<Attachment> att_list=att_Service.search_old_atts_by_req_id(obj.getId());
		if (att_list != null) {
			for (int i = 0; i < att_list.size(); i++) {
				Attachment att_tmp = att_list.get(i);
				String att_status=att_tmp.getAtt_status();
				String check_status="接收需求";
				if (i==att_list.size()) {
					if (att_status.equals(check_status)) {
						old_att=old_att+"{type:'block',list:["
								+"{type : 'label', name:'"+att_tmp.getAtt_file_name()+"',labelWidth:'200', label:'"+att_tmp.getAtt_file_name()+"'},"
								+"{type : 'newcolumn'},"
								+"{type : 'button',name : 'download_"+att_tmp.getId()+"',value : '下载'}"
						+"]}";	
					} else {
						old_att=old_att+"{type:'block',list:["
								+"{type : 'label', name:'"+att_tmp.getAtt_file_name()+"',labelWidth:'200', label:'"+att_tmp.getAtt_file_name()+"'},"
								+"{type : 'newcolumn'},"
								+"{type : 'button',name : 'download_"+att_tmp.getId()+"',value : '下载'},"
								+"{type : 'newcolumn'},"
								+"{type : 'button',name : 'del_"+att_tmp.getId()+"',value : '删除'}"
						+"]}";	
					}
					
				} else {
					if (att_status.equals(check_status)) {
						old_att=old_att+"{type:'block',list:["
												+"{type : 'label', name:'"+att_tmp.getAtt_file_name()+"',labelWidth:'200', label:'"+att_tmp.getAtt_file_name()+"'},"
												+"{type : 'newcolumn'},"
												+"{type : 'button',name : 'download_"+att_tmp.getId()+"',value : '下载'}"
										+"]},";	
					} else {
						old_att=old_att+"{type:'block',list:["
								+"{type : 'label', name:'"+att_tmp.getAtt_file_name()+"',labelWidth:'200', label:'"+att_tmp.getAtt_file_name()+"'},"
								+"{type : 'newcolumn'},"
								+"{type : 'button',name : 'download_"+att_tmp.getId()+"',value : '下载'},"
								+"{type : 'newcolumn'},"
								+"{type : 'button',name : 'del_"+att_tmp.getId()+"',value : '删除'}"
						+"]},";	
					}

				}
				
			}
		}
		
		String g_node_date="";
		String node_value=req_base_info_obj.getNode_value();
		if(node_value!=null){
			Date get_node_date=req_bill_Service.search_node_value_date_by_req_id_and_value(obj.getId(),node_value);
			if(get_node_date!=null){
				g_node_date=sdf.format(get_node_date);
			}
		}
		
		
		String r_start="["
						+ "{type: 'block', label: '分配需求',  list:["
										+"{type:'block',list:["						
											+"{type : 'hidden',name : 'req_id',label : '需求ID',labelWidth:'70',position:'label-left', value:'"+obj.getId()+"'}"
										+"]},"
										+"{type:'block',list:["
												+"{type : 'select',name : 'req_orientation',label : '需求定位',inputWidth:'150', required:'true',value:'"+req_base_info_obj.getReq_orientation()+"',options:["
														+"{text: '', value: ''},"
														+"{text: '项目需求', value: '项目需求'},"
														+"{text: '功能需求', value: '功能需求'},"
														+"{text: '参数配置', value: '参数配置'},"
														+"{text: '缺陷转需求',value: '缺陷转需求'},"
														+"{text: '其他',value: '其他'}"
												+ "]},"
												+"{type : 'newcolumn'},"
												+"{type : 'select',name : 'req_difficult',label : '需求难度',inputWidth:'150', required:'true',offsetLeft:'25',value:'"+req_base_info_obj.getReq_difficult()+"', options:["
														+"{text: '', value: ''},"
														+"{text: '大', value: '大'},"
														+"{text: '中', value: '中'},"
														+"{text: '小', value: '小'}"
												+ "]},"
												+"{type : 'newcolumn'},"
												+"{type : 'input',name : 'technical_director',label : '技术负责人',inputWidth:'150',position:'label-left',value:'"+g_Technical_director+"', offsetLeft:'25'}"
										+"]},"											
										+"{type:'block',list:["
												+"{type : 'calendar',name : 'req_plan_date',label : '计划完成日',position:'label-left', inputWidth:'130', value:'"+g_plan_date+"', required:'true'},"
												+"{type : 'newcolumn'},"
												+"{type : 'input',name : 'req_workload',label : '计划工作量',inputWidth:'100',position:'label-left', required:'true',value:'"+req_base_info_obj.getReq_workload()+"',offsetLeft:'25'},"
												+"{type : 'newcolumn'},"
												+"{type : 'input',name : 'workload_unit',label : '人天',inputWidth:'0',position:'label-left',disabled:'true',value:''},"
												+"{type : 'newcolumn'},"
												+"{type : 'select',name : 'req_status',label : '需求状态',inputWidth:'150',labelWidth:'70',position:'label-left', required:'true',offsetLeft:'25',value:'"+obj.getReq_status()+"',options:["
													+"{text: '已接收', value: '已接收'},"
													+"{text: '已分配', value: '已分配'},"
													+"{text: '已退回', value: '已退回'},"
													+"{text: '已完成', value: '已完成'}"
												+ "]},"
											+"]},"
										+"{type:'block',list:["
											+"{type : 'calendar',name : 'actual_finish_date',label : '实际完成日',position:'label-left', inputWidth:'150', value:'"+g_act_date+"'},"
											+"{type : 'newcolumn'},"
											+"{type : 'input',name : 'req_actual_workload',label : '实际工作量',inputWidth:'100',position:'label-left', disabled:'true',value:'"+g_act_workload+"',offsetLeft:'25'},"
											+"{type : 'newcolumn'},"
											+"{type : 'input',name : 'workload_unit',label : '人天',inputWidth:'0',position:'label-left',disabled:'true',value:''},"
											+"{type : 'newcolumn'}"											
										+"]},"
										+"{type:'block',list:["
											+"{type : 'select',name : 'node_value',label : '项目节点',inputWidth:'150',labelWidth:'70',position:'label-left', required:'true',value:'"+req_base_info_obj.getNode_value()+"',options:["
												+"{text: '', value: ''},"
												+"{text: '1领取需求', value: '1领取需求'},"
												+"{text: '2提交需求', value: '2提交需求'},"
												+"{text: '3开始开发', value: '3开始开发'},"
												+"{text: '4系统测试', value: '4系统测试'},"
												+"{text: '5应用测试', value: '5应用测试'},"
												+"{text: '6完成测试', value: '6完成测试'},"
												+"{text: '7完成上线', value: '7完成上线'},"
												+"{text: '8结束跟踪', value: '8结束跟踪'}"
											+ "]},"	
											+"{type : 'newcolumn'},"
											+"{type : 'calendar',name : 'node_value_date',label : '节点对应时间',position:'label-left', inputWidth:'150', required:'true',offsetLeft:'25',value:'"+g_node_date+"'}"
										+"]},"
										+"{type:'block',list:["
											+"{type : 'editor',name : 'req_introduction',label : '方案简介',position:'label-top', inputWidth:'800', inputHeight:'200',value:''},"
											+"{type : 'editor',name : 'req_remark',label : '备注说明',position:'label-top', inputWidth:'800', inputHeight:'200',value:''}"										
										+"]},"
										+ "{type: 'fieldset', label: '已上传附件',  list:["
											+old_att												
										+"]},"	
										+"{type:'fieldset',label:'附件',list:["
											+"{type : 'label', name:'att_label', label:'上传文件最大值: 100 Mb'},"
											+"{type:'upload', name:'myFiles', inputWidth:'400', titleText:'拖拽文件到此区域或点击选择文件上传', url:'/attachment/upload', _swfLogs:'enabled',  autoStart:'true', swfPath:'/common/uploader.swf',  swfUrl:'attachment/upload'}"
										+"]},"					
										+"{type:'block',list:["
											+"{type : 'input',name : 'att_group_id',label : 'att_group_id',inputWidth:'150',position:'label-left', hidden:'true',offsetLeft:'25'},"
											+"{type : 'input',name : 'att_id',label : 'att_id',inputWidth:'150',position:'label-left', hidden:'true', offsetLeft:'25'}"										
										+"]},"
										+"{type:'block',list:["
											+"{type : 'button',name : 'base_info_save_btn',value : '保存修改信息'}"
											//+"{type : 'newcolumn'},"
											//+"{type : 'button',name : 'assign_btn2',value : '退回'}"										
										+"]}"											
										//+"{type:'block',list:["
										//	+"{type : 'input',name : 'req_title',label : '需求主题',labelWidth:'70', inputWidth='700',position:'label-left', disabled:'true',value:'"+obj.getReq_title()+"'}"
										//+"]}"
									+"]"
							+ "}"
						+"]";
		String r_s=r_start;
		logger.info("retrun info :" + r_start);
		return r_s;
	}
}
